package org.mypofolio.gui;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

public class MyPofolioCellRenderer extends DefaultTableCellRenderer {
	  
    private SimpleDateFormat sd=new SimpleDateFormat("dd/MM/yyyy");
	
	protected void setValue(Object value) {
		
		    if (value instanceof DataWithIcon) {
		      if (value != null) {
		        DataWithIcon d = (DataWithIcon)value;
		        Object dataValue = d.getData();

		        setText(dataValue == null ? "" : dataValue.toString());
		        setIcon(d.getIcon());
		        setHorizontalTextPosition(SwingConstants.RIGHT);
		        setVerticalTextPosition(SwingConstants.CENTER);
		        setHorizontalAlignment(SwingConstants.LEFT);
		        setVerticalAlignment(SwingConstants.CENTER);
		      } else {
		        setText("");
		        setIcon(null);
		      }
		    } else if (value != null && value instanceof Date) {
			      setText(sd.format(value));
		    }else{
		      super.setValue(value);
		    }
		    
	  }
	
		           

}
